package com.magina.antiPro.handler;


import com.magina.antiPro.exception.BusinessException;
import com.magina.antiPro.response.Response;
import com.magina.antiPro.util.StringUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.persistence.EntityNotFoundException;
import java.lang.reflect.Method;
import java.util.concurrent.ExecutionException;

@Slf4j
public class AsyncExpectionHandler implements AsyncUncaughtExceptionHandler {

    public void handleUncaughtException(Throwable ex, Method method, Object... params) {
//        log.info("Async method: {} has uncaught exception,params:{}", method.getName(), JSON.toJSONString(params));

        if (ex instanceof BusinessException ) {
            BusinessException  asyncException = (BusinessException ) ex;
            log.info("asyncException:{}",asyncException.getMessage());
        }
        log.info("Exception :");
        ex.printStackTrace();
    }
}